<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script>
    <script type="text/javascript" src="../../src/objx.test.js"></script>
    <script type="text/javascript" src="../../src/objx.js"></script>
    <script type="text/javascript"><!--
    
        // TODO: add tests to make sure other base classes and interfaces work
        // with abstract classes.

        function test_exceptionThrown_whenTyingToInstantiateAnAbstractClass()
        {
return;
            var AClass = Class(Abstract({
            
                baseMethod: function(){
                    return 123;
                }
            
            }));
            
            assertThrowsType("Instantiating an abstract class should throw an exception.", 
                objx.exceptions.ClassException, function(){

                var instance = new AClass();
            
            });
        
        }
        
        function test_throwsException_whenDeclaringAMethodInANonAbstractClass()
        {
return;
            assertThrowsType("Declaring a non-abstract class with Method() placeholders should throw an exception.", 
                objx.exceptions.DefinitionException, function(){
            
                var MyClass = Class({
                
                    doSomething: function(){},
                    doSomethingElse: Method()
                
                });
                
            });
        
        }
        
        function test_abstractClassSubclassShouldImplementAnyMethods()
        {
return;
            var AClass = Class(Abstract({
            
                baseMethod: function(){
                    return 123;
                },
                
                getName: Method(0)
            
            }));
            
            assertThrowsType("Trying to subclass an abstract class without implementing the specified methods should result in DefinitionException being thrown but did not",
                objx.exceptions.DefinitionException, function(){
                    var SubClassOne = Class(AClass, {
                    }); 
                }
            );

            assertThrowsType("Trying to subclass an abstract class without the methods matching exactly should result in an exception but did not",
                objx.exceptions.DefinitionException, function(){
                    var SubClassInvalid = Class(AClass, {
                        getName: function(thisShouldntBeHere){}
                    });
                }
            );

            assertThrowsType("Trying to subclass an abstract class without implementing the specified methods should result in DefinitionException being thrown but did not",
                objx.exceptions.DefinitionException, function(){
                    var SubClassOne = Class(AClass, {
                    }); 
                }
            );

            assertNotThrows("Subclassing an abstract class and getting all the virtual methods right should NOT result in an exception, but did!", function(){
            
                var SubClassValid = Class(AClass, {
                    getName: function(){}
                });
            
            });
            
        }
        
        function test_typeCorrectOnclassesWithAbstractBase(){

        	var AbstractBase = AbstractClass({});
        	var Subclass = Class(AbstractBase, {});
        	
        	var instanceOfSubclass = new Subclass();

        	assertEquals("Instances of Class with abstract base has abstract base as 'type' instead of sub-class.", Subclass, instanceOfSubclass.type);
        
        }
        
        function test_abstractClassFieldsInherited(){
        
        	var AbstractBase = AbstractClass({
        		field: 123
        	});
        	var Subclass = Class(AbstractBase, {
        	});
        	var SubclassTwo = Class(AbstractBase, {
        		field: 456
        	});
        	
        	var instanceOfSubclass = new Subclass();

        	assertEquals("AbstractBase.prototype.field not set.", 123, AbstractBase.prototype.field);
        	assertEquals("Subclass.prototype.field didn't inherit from AbstractBase.prototype.field", 123, Subclass.prototype.field);
        	assertEquals("instanceOfSubclass.field didn't inherit from AbstractBase.prototype.field", 123, instanceOfSubclass.field);
        
        	assertEquals("SubclassTwo.field didn't overwrite inherited AbstractBase.prototype.field", 456, SubclassTwo.prototype.field);

        }

    </script>
</head>
<body>
</body>
</html>